package com.food.controller.user;

import com.food.dto.ShoppingCartDTO;
import com.food.entity.ShoppingCart;
import com.food.result.Result;
import com.food.service.ShoppiingCartService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.experimental.FieldNameConstants;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user/shoppingCart")
@Api(tags = "c端购物车相关接口")
@Slf4j
public class ShoppingCartController {

    @Autowired
    private ShoppiingCartService shoppiingCartService;
    /**
     * 添加购物车
     * @param shoppingCartDTO
     * @return
     */
    @PostMapping("/add")
    @ApiOperation("添加购物车")
    public Result  add(@RequestBody  ShoppingCartDTO shoppingCartDTO){
        shoppiingCartService.addShoppingCart(shoppingCartDTO);
        return Result.success();
    }

    /**
     * 查看购物车
     * @return
     */
    @GetMapping("/list")
    @ApiOperation("查看购物车")
    public  Result<List<ShoppingCart>> list(){
        List<ShoppingCart> list=shoppiingCartService.showShoppingCart();
        return  Result.success(list);
    }

    /**
     * 清空购物车
     * @return
     */
    @DeleteMapping("/clean")
    @ApiOperation("清空购物车")
    public  Result  clean(){
       shoppiingCartService.cleanShoppingCart();
        return  Result.success();
    }


    /**
     * 删除购物车单个商品
     * @return
     */
    @PostMapping ("/sub")
    @ApiOperation("删除购物车单个商品")
    public  Result  deleteById(@RequestBody ShoppingCartDTO shoppingCartDTO){
        shoppiingCartService.deleteShoppingById(shoppingCartDTO);
        return  Result.success();
    }


}
